using UnityEngine;
using System.Collections;

public class Projetil_Comportamento : MonoBehaviour {

	public float Velocity;
	float cronometro = 0;
	public float lifeTime;
	public string enemyTag; 
	void Awake () 
	{
		
	}
	void Update () 
	{
		cronometro += Time.deltaTime;
		
		if(cronometro > lifeTime)
		{
			Destroy(gameObject);
		}
		transform.Translate(new Vector3(Velocity, 0, 0)*Time.deltaTime);
		
		
	}
	void OnTriggerStay(Collider collider)
	{
		
		if(collider.tag.Equals(enemyTag))
		{
			Destroy(collider.gameObject);
		}
		if(!collider.tag.Equals("GamePlayer")){
		float newDirection = Random.Range(0,-180);
		float newYDirection = Random.Range(0,180);
		transform.localEulerAngles = new Vector3(transform.localEulerAngles.x,newYDirection, transform.localEulerAngles.z + newDirection);
		}
		
	}
}
